package cn.jk.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

//@Component
public class MyEventListener {

	@EventListener({MyApplicationEvent.class})
	@Async // 异步执行
	@Order(12)
	public void processMyEvent(){
		System.out.println("接受到了自定义事件");
	}

	/**
	 *
	 *	EventListener还支持条件过滤
	 */
	@EventListener
	@Order(11)
	public void processApplicationContextEvent(ApplicationContextEvent event){
		System.out.println("接受到了ApplicationContextEvent " + event.getClass().getName() + " " + event.hashCode());
	}

	@EventListener
	public void processMyApplicationContextEvent(MyApplicationEvent<Integer> event){
		System.out.println("触发了泛型的事件机制");
	}
}
